#include <CUnit/CUnit.h>
#include "../cue.h"

static void
test_cd_is_created_and_destroyed()
{
	struct cue_cd *cd;

	cd = create_cue_cd();
	CU_ASSERT_PTR_NOT_NULL(cd);

	destroy_cue_cd(cd);
}

static void
test_tracks_are_added_to_cd()
{
	struct cue_cd *cd;
	struct cue_track *track;
	int res;

	cd = create_cue_cd();
	CU_ASSERT_EQUAL(get_cue_tracks_count(cd), 0);

	track = create_cue_track();
	res = add_cue_track(cd, track);
	CU_ASSERT_EQUAL(res, 0);
	CU_ASSERT_EQUAL(get_cue_tracks_count(cd), 1);
	CU_ASSERT_PTR_EQUAL(get_cue_track(cd, 0), track);

	destroy_cue_cd(cd);
}

static void
test_get_cue_track_returns_null_when_index_is_out_of_bounds()
{
	struct cue_cd *cd;

	cd = create_cue_cd();
	CU_ASSERT_PTR_NULL(get_cue_track(cd, 0));
	destroy_cue_cd(cd);
}

static void
test_parts_are_added_to_track()
{
	struct cue_track *track;
	struct cue_track_part *part;
	int res;

	track = create_cue_track();
	CU_ASSERT_EQUAL(get_cue_track_parts_count(track), 0);

	part = create_cue_track_part();
	res = add_cue_track_part(track, part);
	CU_ASSERT_EQUAL(res, 0);
	CU_ASSERT_EQUAL(get_cue_track_parts_count(track), 1);
	CU_ASSERT_PTR_EQUAL(get_cue_track_part(track, 0), part);

	destroy_cue_track(track);
}

static void
test_get_cue_track_part_returns_null_when_index_is_out_of_bounds()
{
	struct cue_track *track;

	track = create_cue_track();
	CU_ASSERT_PTR_NULL(get_cue_track_part(track, 0));
	destroy_cue_track(track);
}

void
add_cue_test_suite()
{	
	CU_pSuite result;

	result = CU_add_suite("cue", NULL, NULL);

	CU_ADD_TEST(result, test_cd_is_created_and_destroyed);
	CU_ADD_TEST(result, test_tracks_are_added_to_cd);
	CU_ADD_TEST(result, test_get_cue_track_returns_null_when_index_is_out_of_bounds);
	CU_ADD_TEST(result, test_parts_are_added_to_track);
	CU_ADD_TEST(result, test_get_cue_track_part_returns_null_when_index_is_out_of_bounds);
}

